# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=lightdm
pkgver=1.30.0
pkgrel=5
pkgdesc="cross-desktop display manager"
url="https://www.freedesktop.org/wiki/Software/LightDM"
# riscv64 disabled due to missing rust in recursive dependency
arch="all !s390x !riscv64" # gnome-themes-standard missing due to librsvg
license="GPL-3.0-or-later"
depends="dbus xinit accountsservice gnome-themes-standard
	adwaita-icon-theme"
makedepends="linux-pam-dev gtk+3.0-dev libxext-dev libxklavier-dev
	autoconf automake libtool gobject-introspection-dev itstool
	libgcrypt-dev libxml2-utils intltool qt5-qtbase-dev vala"
install="$pkgname.pre-install"
pkgusers="lightdm"
pkggroups="lightdm"
subpackages="
	$pkgname-dev
	$pkgname-doc
	$pkgname-lang
	$pkgname-openrc
	$pkgname-qt5
	$pkgname-qt5-dev:qt5_dev
	$pkgname-bash-completion:bashcomp:noarch
	"
source="https://github.com/CanonicalLtd/lightdm/releases/download/$pkgver/lightdm-$pkgver.tar.xz
	musl-language.patch
	musl-is-linux.patch
	musl-updwtmpx.patch
	disallow-guest.patch
	allow-null-passwd.patch
	auto-unlock-keyring.patch
	lightdm.initd"

build() {
	export CFLAGS="$CFLAGS -D_GNU_SOURCE"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sbindir=/usr/bin \
		--sysconfdir=/etc \
		--localstatedir=/var \
		--disable-tests \
		--enable-vala \
		--with-greeter-session=lightdm-gtk-greeter

	make
}

package() {
	make DESTDIR="$pkgdir" install
	sed -i "s/pam_systemd/pam_elogind/" "$pkgdir"/etc/pam.d/*
	ln -s /etc/X11/xinit/Xsession "$pkgdir"/usr/bin/lightdm-session
	install -Dm755 "$srcdir"/lightdm.initd "$pkgdir"/etc/init.d/lightdm
	install -o lightdm -g lightdm -d "$pkgdir"/var/lib/lightdm-data
	rm -rf "$pkgdir"/etc/apparmor.d

	# Fix location of dbus configuration from $sysconfdir to $datadir
	mv "$pkgdir"/etc/dbus-1/system.d "$pkgdir"/usr/share/dbus-1/system.d
	rm -rf "$pkgdir"/etc/dbus-1
}

qt5() {
	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/liblightdm-qt5* "$subpkgdir"/usr/lib
}

qt5_dev() {
	mkdir -p "$subpkgdir"/usr/lib/pkgconfig "$subpkgdir"/usr/include
	mv "$pkgdir"/../$pkgname-dev/usr/include/lightdm-qt5-3 "$subpkgdir"/usr/include/
	mv "$pkgdir"/../$pkgname-dev/usr/lib/liblightdm-qt5-3.* "$subpkgdir"/usr/lib/
	mv "$pkgdir"/../$pkgname-dev/usr/lib/pkgconfig/liblightdm-qt5-3.pc "$subpkgdir"/usr/lib/pkgconfig/
}

bashcomp() {
	depends=""
	pkgdesc="Bash completions for $pkgname"
	install_if="$pkgname=$pkgver-r$pkgrel bash-completion"

	amove usr/share/bash-completion/completions
}

sha512sums="bca25a0aa73caf7d51e5882889a1707d2527470a170658c1be98ecfb96c8f85fd616494fc5bed658e744f91b9f8b0a98d2a0cf42f9c030242ae470c8a27145ce  lightdm-1.30.0.tar.xz
592d630bdabeed304f8b677ceb0ebd2a6ab0930baae473814aafb0d58b7e28a79c8c667f18a656a460132c48a9fee90be7eebd50f835ea641d6d99387b28310a  musl-language.patch
aa33888f61b61f6c8082c77dc0b539fa14fb395c17e70b825ba88af7bb6adaad8f99583342a77442c60c105c1b83dd6eb0547fbddb43dcd767d9ad2c65ca2baf  musl-is-linux.patch
876088f21e502630c7d13343b03785d3327727c25657690c8e1cff5428a36944eb75d538f24ab4f5b11f931d8fad51241f25046da370eb5868aa8d2860be4eb2  musl-updwtmpx.patch
c5bf8cfc0b4c4f95d9c9a3fa517b6c8ec90e02d84fb4498176b4745ed6089576fab536e9a3595200443811f05f2d47ac5e7c0205c878d9c23eff4dda7093ad6c  disallow-guest.patch
7d31a5d7034e665a86a7067654c8865fa5db98b58c32afab6077d589c0cd1351bfbfb4625e5e1b2ccf8c98bc08e7c97412c528311c3c32da0b8e45916f8de767  allow-null-passwd.patch
24771daeb48af67d5f922cce3d5b784fdccbda3aed26f3b788f7ba5539e6681ab7d74863e103067029f0ec3f1313fd8bd1fd5a8c860208958561cbf3956c87d8  auto-unlock-keyring.patch
b9d0a172b2a6964e9896cfc95371e53525c21758f711b50b96a5e4bb5409bcddc0083b027819c9e751dbc7b88d6280dc62402e596c1a173036071889fb0f0685  lightdm.initd"
